Structures: Initialisation |
Pascal C/C++
NO STANDARD |
PASCAL EQUIVALENT
(BUT MANY |
DIALECTS ALLOW |
THIS) |
A C variable may be initialised
when it is declared – e.g. |
int i = 3; |
char c = ‘A’; |
float a[3] = {1.0, 2.0, 3.0}; |
struct |
{ char name[11]; |
float gpa; |
} student = {“Smith”, 4.0}; |
NOTE: In C++, initialisation of a struct this way is not |
allowed if any field is of class type, requiring a constructor.